package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.ysd.entity.Admin;
import com.ysd.util.DBManager;
import com.ysd.util.Result;
/**
 * 根据账号查询信息
 * @author Administrator
 *
 */
public class AdminDaoImpl {
	public Admin getAdminByUserName(String username) {
		Admin a=null;
		Connection conn=DBManager.getConnection();
		Statement st=null;
		ResultSet rs=null;
		try {
			st=conn.createStatement();
			rs=st.executeQuery("SELECT * FROM admin WHERE username='"+username+"'");
			while(rs.next()) {
				int id=rs.getInt("id");
				String name=rs.getString("username");
				String mima=rs.getString("password");
				a=new Admin(id, name, mima);//构造方法是用来创建对象的，当new时
			}
			return a;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} finally {
			DBManager.closeAll(conn, st, rs);
		}
		
	}
}
